package Text8;

import java.util.*;

public class Main {
    static int N = 110;
    static int[][] w = new int[N][N];
    static int[][] f = new int[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        while (T-- > 0) {
            int n = in.nextInt();
            int m = in.nextInt();
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    w[i][j] = in.nextInt();
                }
            }
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m; j++) {
                    f[i][j] = Math.max(f[i - 1][j], f[i][j - 1]) + w[i][j];
                }
            }
            System.out.println(f[n][m]);
        }
    }
}
